package com.rover.system.entity;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.GenericGenerator;

import com.common.Common;
import com.grid.ViewField;

/**
 * 用户.
 *
 */
@Entity
@Table(name = "S_Users")
public class User  implements Serializable {
	 /**
		 * 
		 */
		private static final long serialVersionUID = 1L;

	    @Id
	    @GeneratedValue(generator = "paymentableGenerator")
	    @GenericGenerator(name = "paymentableGenerator", strategy = "native",
	            parameters = { @org.hibernate.annotations.Parameter(name = "sequence", value = "seq_S_User") })
	    @ViewField
	    private Integer id;

	    @Column(nullable = false, unique = true, length = 20)
	    @ViewField(header = "登录名", width = 150)
	    private String loginName;

	    @Column(length = 100)
	    @ViewField
	    private String password;

	    @Column(length = 50)
	    @ViewField(header = "姓名", width = 200)
	    private String name;

	    @Column(length = 10)
	    @ViewField
	    private int status = Common.ENABLE_STATUS;//默认为启用状态

	    @Column(length = 50)
	    @ViewField(header = "邮箱", width = 250)
	    private String email;


	    @ManyToMany(cascade = CascadeType.REFRESH,fetch = FetchType.LAZY)//用LAZY问题：User不能直接使用user.permissions 会报：com.sun.jdi.InvocationException occurred invoking method.
	    @JoinTable(name = "S_UserRole", joinColumns = @JoinColumn(name = "userId"),inverseJoinColumns = @JoinColumn(name = "roleId") )
	    private Set<Role> roleList;


	    public Integer getId() {
			return id;
		}

		public void setId(Integer id) {
			this.id = id;
		}

		public String getLoginName() {
	        return loginName;
	    }

	    public void setLoginName(String loginName) {
	        this.loginName = loginName;
	    }

	    
	  
	    public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getEmail() {
	        return email;
	    }

	    public void setEmail(String email) {
	        this.email = email;
	    }

	    public int getStatus() {
	        return status;
	    }

	    public void setStatus(int status) {
	        this.status = status;
	    }
	    
		
		public String getPassword() {
	        return password;
	    }

	    public void setPassword(String password) {
	        this.password = password;
	    }

	    public Set<Role> getRoleList() {
	        return roleList;
	    }

	    public void setRoleList(Set<Role> roleList) {
	        this.roleList = roleList;
	    }
}
